Object.isElement = function(object){
    return !!(object && object.nodeType == 1);
};

String.prototype.toHtmlElement = function(){
    var _root = document.createElement('div');
        _root.style.display = "none";
    	_root.innerHTML = this;
		var el = $(_root).getFirst();
		
    return el;
};


/*
 * Returns the object by it's namespace
 * Example:
 * "com::aol::TabControl".ref() will resolve to the 
 *  object store at com.aol.TabControl
 * 
 */
String.prototype.ref = function(){
    var ref = this.replace(/\:{2}/ig,".");
    return eval(ref);
};



/*
 * 
 * Debouncing ensures that exactly one signal is sent for an event that 
 * may be happening several times — or even several hundreds of times 
 * over an extended period. As long as the events are occurring fast 
 * enough to happen at least once in every detection period, the 
 * signal will not be sent!
 * 
 * see: 
 * http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
 */
Function.prototype.debounce = function(threshold, execAsap) {
    var func = this, timeout;
    return function debounced() {
        var obj = this, args = arguments;
        function delayed() {
            if (!execAsap) {
                func.apply(obj, args);}
            timeout = null;
        };
        if (timeout) {
            clearTimeout(timeout);}
        else {
            if (execAsap) {func.apply(obj, args);}
        }
        timeout = setTimeout(delayed, threshold || 100);
    }
};

/*
 * see: http://unscriptable.com/index.php/2009/03/19/hi-performance-javascript-tips-1/#more-108
 * Easily cast objects like function arguments and the DOM childNodes property into
 * a real array.
 */
toArray = (function(s){return function(o){return s.call(o,0)}})([].slice);

//
//$C = function(obj, proto){
//   for(var key in proto) {
//       if(!obj[key]) obj[key] = proto[key];
//   };
//   return obj;
//   
//    /*if(!this.__extended_prototypes) this.__extended_prototypes = [];
//    if(!this.__extended_prototypes.indexOf(obj) >=0) {
//        console.log("extending");
//        var o = js.extend(obj,proto);
//        this.__extended_prototypes.push(obj);
//        return o
//    }
//    else {
//        return this.__extended_prototypes[this.__extended_prototypes.indexOf(obj)];
//    }*/
//};


//Object.extend = function(destination, source) {
//    for (var property in source) {
//            destination[property] = source[property];}
//        return destination;
//};

